package com.weishi.project.training.controller;

import java.util.Date;
import java.util.List;

import com.weishi.project.training.domain.Sportsman;
import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.weishi.framework.aspectj.lang.annotation.Log;
import com.weishi.framework.aspectj.lang.enums.BusinessType;
import java.util.Arrays;
import com.weishi.project.training.domain.LeaveForm;
import com.weishi.project.training.service.ILeaveFormService;
import com.weishi.framework.web.controller.BaseController;
import com.weishi.framework.web.domain.AjaxResult;
import com.weishi.common.utils.poi.ExcelUtil;
import com.weishi.framework.web.page.TableDataInfo;

/**
 * leaveFormController
 */
@Api(value = "请假单",description = "请假单")
@RestController
@RequestMapping("/training/leaveForm")
public class LeaveFormController extends BaseController {

    @Autowired
    private ILeaveFormService leaveFormService;

    /**
     * 查询请假单列表
     */
    @PreAuthorize("@ss.hasPermi('training:leaveForm:list')")
    @GetMapping("/list")
    public TableDataInfo list(LeaveForm leaveForm) {
        startPage();
        List<LeaveForm> list = leaveFormService.selectLeaveFormList(leaveForm);
        return getDataTable(list);
    }

    /**
     * 导出请假单列表
     */
    @PreAuthorize("@ss.hasPermi('training:leaveForm:export')")
    @Log(title = "leaveForm", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LeaveForm leaveForm) {
        List<LeaveForm> list = leaveFormService.selectLeaveFormList(leaveForm);
        ExcelUtil<LeaveForm> util = new ExcelUtil<LeaveForm>(LeaveForm.class);
        return util.exportExcel(list, "leaveForm");
    }

    /**
     * 获取请假单详细信息
     */
    @PreAuthorize("@ss.hasPermi('training:leaveForm:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(leaveFormService.getLeaveFormById(id));
    }

    /**
     * 新增请假单
     */
    @PreAuthorize("@ss.hasPermi('training:leaveForm:add')")
    @Log(title = "leaveForm", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LeaveForm leaveForm) {
        leaveForm.setCtime(new Date());
        leaveFormService.save(leaveForm);
        return AjaxResult.success();
    }

    /**
     * 修改请假单
     */
    @PreAuthorize("@ss.hasPermi('training:leaveForm:edit')")
    @Log(title = "leaveForm", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LeaveForm leaveForm) {
        leaveForm.setLtime(new Date());
        leaveFormService.updateLeaveFormById(leaveForm);
        return AjaxResult.success();
    }

    /**
     * 删除请假单
     */
    @PreAuthorize("@ss.hasPermi('training:leaveForm:remove')")
    @Log(title = "leaveForm", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        leaveFormService.removeByIds(Arrays.asList(ids));
        return AjaxResult.success();
    }

    /**
     * 查询运动员姓名集合
     */
    @GetMapping("/queryNamelist")
    public TableDataInfo querySportsNameList() {
        startPage();
        List<Sportsman> list = leaveFormService.querySportsNameList();
        return getDataTable(list);
    }
    
}